package com.shengyuan.manage_os.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import android.widget.Toast;

import com.shengyuan.manage_os.R;
import com.shengyuan.manage_os.utils.GridViewTools;
import com.shengyuan.manage_os.view.CircleImageView;
import com.shengyuan.manage_os.view.MyGridView;

/**
 * Created by Administrator on 2016/11/18.
 */

public class MomentsAdapter extends BaseAdapter {
    private Context context;
    private ViewHol viewHol;
    private GridViewTools tools;
    public MomentsAdapter(Context context){
        this.context = context;
//        viewHol = new ViewHol();
        tools = new GridViewTools(context);
    }
    @Override
    public int getCount() {
        return 10;
    }

    @Override
    public Object getItem(int i) {
        return i;
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {

        final int pos = i;
        if(view == null){
            view = LayoutInflater.from(context).inflate(R.layout.moments_list_layout,null);
            viewHol = new ViewHol();
            viewHol.hear = (CircleImageView) view.findViewById(R.id.hear);
            viewHol.name = (TextView) view.findViewById(R.id.name);
            viewHol.time = (TextView) view.findViewById(R.id.time);
            viewHol.content = (TextView) view.findViewById(R.id.content);
            viewHol.pinglun = (TextView) view.findViewById(R.id.pinglun);
            viewHol.dianzan = (TextView) view.findViewById(R.id.dianzan);
            viewHol.zhuanfa = (TextView) view.findViewById(R.id.zhuanfa);
            viewHol.gridView = (MyGridView) view.findViewById(R.id.tupian_item);
            view.setTag(viewHol);
        }else {
            viewHol = (ViewHol) view.getTag();
        }

        if(i==4)
            tools.setGviewData(viewHol.gridView);
        else
        viewHol.gridView.setAdapter(null);

        viewHol.dianzan.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(context,"点赞"+pos,Toast.LENGTH_LONG).show();
            }
        });


        return view;
    }
}

class ViewHol{
    public CircleImageView hear;
    public TextView name;
    public TextView time;
    public TextView content;
    public TextView pinglun;
    public TextView zhuanfa;
    public TextView dianzan;
    public MyGridView gridView;

}
